package site.teamo.biu.net.server.configuration;

import jakarta.annotation.Resource;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import site.teamo.biu.net.common.web.interceptor.UserInterceptor;
import site.teamo.biu.net.server.interceptor.ReportInterceptor;

@Configuration
public class WebConfig implements WebMvcConfigurer {

    @Resource
    private UserInterceptor userInterceptor;

    @Resource
    private ReportInterceptor reportInterceptor;

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        String[] excludePathPattern = new String[]{
                "/exception",
                "/doc.html",
                "/webjars/**",
                "/v3/**",
                "/api/passport/login",
                "/api/passport/generate-captcha",
                "/api/client-management/access",
                "/api/client-management/report",
                "/",
                "/ui/**"
        };
        registry.addInterceptor(userInterceptor)
                .excludePathPatterns(excludePathPattern);

        String[] includePathPattern = new String[]{
                "/api/client-management/report"
        };
        registry.addInterceptor(reportInterceptor)
                .addPathPatterns(includePathPattern);
    }
}
